package com.example.a2205douyin.fragment;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.widget.ViewPager2;

import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;

import com.example.a2205douyin.R;
import com.example.a2205douyin.adapter.MyFragAdapter;
import com.example.a2205douyin.baseMVVM.view.BaseViewFragment;
import com.example.a2205douyin.databinding.FragmentMineBinding;
import com.google.android.material.bottomnavigation.BottomNavigationView;

import java.util.ArrayList;
import java.util.List;


public class MineFragment extends BaseViewFragment<FragmentMineBinding> {
    List<Fragment> list = new ArrayList<>();
    MyFragAdapter myFragAdapter;

    public MineFragment() {
        // Required empty public constructor
    }


    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {
        list.add(new ShoucangFragment());
        list.add(new XihuanFragment());

        myFragAdapter = new MyFragAdapter(getActivity(),list);
        binding.vp.setAdapter(myFragAdapter);
        //上下联动
        binding.vp.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
            @Override
            public void onPageSelected(int position) {
                super.onPageSelected(position);
                binding.bottom.getMenu().getItem(position).setChecked(true);
            }
        });
        binding.bottom.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                switch (item.getItemId()){
                    case R.id.shoucang:
                        binding.vp.setCurrentItem(0);
                        break;
                    case R.id.xihuan:
                        binding.vp.setCurrentItem(1);
                        break;
                }
                return false;
            }
        });
    }

    @Override
    protected int getLayout() {
        return R.layout.fragment_mine;
    }
}